//#version 130
//
//uniform sampler2D tex0;
//
//uniform float CA[12];
//uniform float LA[12];
//uniform float QA[12];
//uniform vec3 PLDif[12];
//uniform vec3 PLSpec[12];
//uniform vec3 PLPos[12];
//uniform int numbOfPL;
//
//in vec4 fColor;
//in vec3 fNormal;
//in vec2 fTexCoord;
//in vec3 fVertPos;
//
//out vec4 fOut;
//
//void main()
//{	
	////vec3 baseColor = texture2D(tex0, fTexCoord).xyz;
	//const vec3 baseColor = vec3(1.0, 1.0, 1.0);
	//vec3 color = vec3(0.0, 0.0, 0.0);
	//vec3 eye = normalize (-fVertPos); // cam in 0,0,0 cause were in eyespace 
	//for ( int i = 0; i < numbOfPL; i++)	
	//{
		//vec3 currentPLDir = PLPos[i] - fVertPos;
		//float distL = length(currentPLDir);
		//float att = 1.0 / (CA[i] + distL * LA[i] + distL * distL * QA[i]);
		//currentPLDir = normalize(currentPLDir);
		//float NDOTL = max(0.0, dot(currentPLDir, fNormal));
		//
		//vec3 refl = normalize(((2.0 * fNormal) * NDOTL) - currentPLDir);
		//float FDOTE = max(0.0, dot(refl, eye));
//
		//color += baseColor * NDOTL * PLDif[i] * att;
//
		//if (NDOTL > 0)
		//{
			//color += PLSpec[i] * att * pow(FDOTE, 36);
		//}
	//}
	//
	//fOut = vec4(color, 1.0);
	////fOut = vec4(baseColor, 1.0);
//
	////fOut = mix(texture2D(texSampler, fTexCoord), fColor, 0.5);;
//}
//


#version 130

uniform sampler2D tex0;

uniform float CA[12];
uniform float LA[12];
uniform float QA[12];
uniform vec3 PLDif[12];
uniform vec3 PLSpec[12];
uniform vec3 PLPos[12];
uniform int numbOfPL;

in vec4 fColor;
in vec3 fNormal;
in vec2 fTexCoord;
in vec3 fVertPos;

out vec4 fOut;

void main()
{
//vec3 baseColor = texture2D(tex0, fTexCoord).xyz;
const vec3 baseColor = vec3(0.7, 0.7, 0.7);
vec3 color = vec3(0.0, 0.0, 0.0);
vec3 eye = normalize (-fVertPos); // cam in 0,0,0 cause were in eyespace
for ( int i = 0; i < numbOfPL; i++)
{
vec3 currentPLDir = PLPos[i] - fVertPos;
float distL = length(currentPLDir);
float att = 1.0 / (CA[i] + distL * LA[i] + distL * distL * QA[i]);
currentPLDir = normalize(currentPLDir);
float NDOTL = max(0.0, dot(currentPLDir, fNormal));

vec3 refl = normalize(((2.0 * fNormal) * NDOTL) - currentPLDir);
float FDOTE = max(0.0, dot(refl, eye));

color += baseColor * NDOTL * PLDif[i] * att;

if (NDOTL > 0)
{
color += PLSpec[i] * att * pow(FDOTE, 36);
}
}

fOut = vec4(color, 1.0);
//fOut = vec4(baseColor, 1.0);

//fOut = mix(texture2D(texSampler, fTexCoord), fColor, 0.5);;
}

